#include <termParse.h>

int termParseInit(void *tpsPtr, uint8_t bufSize)
{
    termParseStc *tmptps = (termParseStc *)tpsPtr;
    tmptps->parseStep = 0;
    tmptps->packSize = bufSize - offsetof(termParseStc, packData);
    return 0;
}
int termParseUpdate(void *tpsPtr, uint8_t indata)
{
    termParseStc *tmptps = (termParseStc *)tpsPtr;
    int tmpParseOk = 0;
    switch (tmptps->parseStep)
    {
    case 0:
    default:
    {
        tmptps->rcvSize = 0;
        tmptps->parseStep = 1;
        memset(tmptps->packData, 0, tmptps->packSize);
    }
    case 1:
    {
        if(tmptps->rcvSize >= tmptps->packSize)
        {
            logerrorc("rcv over:%d >= %d", tmptps->rcvSize, tmptps->packSize);
            tmptps->parseStep = 0;
            break;
        }
        tmptps->packData[tmptps->rcvSize++] = indata;
        if(indata == '\n')
        {
            tmpParseOk = 1;
            tmptps->parseStep = 0;
            break;
        }
        break;
    }
    }
    return tmpParseOk;
}

